using System;

namespace CinemaDirector
{
	[CutsceneItem("UI", "Add Text")]
	public class GGActionAddTextEvent : CinemaGlobalEvent
	{
		public UILabel from;

		public UILabel to;

		public override void Trigger()
		{
			string text = from.text;
			string text2 = to.text;
			int value;
			if (!TryParseValue(text, out value))
			{
				return;
			}
			int value2;
			if (!TryParseValue(text2, out value2))
			{
				to.text = text;
				return;
			}
			int num = value + value2;
			if (num >= 1000000 && num % 1000000 == 0)
			{
				to.text = num / 1000000 + "M";
			}
			else if (num >= 1000 && num % 1000 == 0)
			{
				to.text = num / 1000 + "k";
			}
			else
			{
				to.text = num.ToString();
			}
		}

		private bool TryParseValue(string valueStr, out int value)
		{
			int num = 1;
			valueStr = valueStr.Replace(" ", string.Empty);
			if (valueStr.EndsWith("M", StringComparison.CurrentCultureIgnoreCase))
			{
				num = 1000000;
				valueStr = valueStr.Substring(0, valueStr.Length - 1);
			}
			if (valueStr.EndsWith("k", StringComparison.CurrentCultureIgnoreCase))
			{
				num = 1000;
				valueStr = valueStr.Substring(0, valueStr.Length - 1);
			}
			if (!int.TryParse(valueStr, out value))
			{
				return false;
			}
			value *= num;
			return true;
		}
	}
}
